export const goPath = (link: string) => {
    if (link) {
        window.location.href = link;
    }
};

export const openURL = (link: string) => {
    if (link) {
        window.open(link);
    }
};

type HashParams = {
    link?: string;
    hash: string;
};
export const goHash = (data: HashParams) => {
    const { link, hash } = data;

    if (link === window.location.href || link === window.location.pathname || !link) {
        window.location.hash = hash;
    } else {
        window.location.hash = hash || '';
        window.location.pathname = link;
    }
};

export const useHash = () => {
    const hash = window.location.hash;
    if (hash) {
        document.getElementById(hash.replace('#', ''))?.scrollIntoView();
    }
};
